#-
# ==========================================================================
# Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors.  All 
# rights reserved.
#
# The coded instructions, statements, computer programs, and/or related 
# material (collectively the "Data") in these files contain unpublished 
# information proprietary to Autodesk, Inc. ("Autodesk") and/or its 
# licensors, which is protected by U.S. and Canadian federal copyright 
# law and by international treaties.
#
# The Data is provided for use exclusively by You. You have the right 
# to use, modify, and incorporate this Data into other products for 
# purposes authorized by the Autodesk software license agreement, 
# without fee.
#
# The copyright notices in the Software and this entire statement, 
# including the above license grant, this restriction and the 
# following disclaimer, must be included in all copies of the 
# Software, in whole or in part, and all derivative works of 
# the Software, unless such copies or derivative works are solely 
# in the form of machine-executable object code generated by a 
# source language processor.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 
# AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED 
# WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF 
# NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 
# PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR 
# TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS 
# BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, 
# DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK 
# AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY 
# OR PROBABILITY OF SUCH DAMAGES.
#
# ==========================================================================
#+

#
#  Autodesk Script File
#  MODIFY THIS AT YOUR OWN RISK
#
#  Creation Date:   27 September 2006
#
#  Description:
#     This script creates a new top level Maya menu that contains a
#	   single item "Move in Circle".  When selected, it will create
#     a sphere and a dependency node that moves this in a circle,
#     and connect these 2 together.
#
#     When the play button on the time slider is pressed, the sphere
#     will move in a cirle around the Y axis.
#
#  Procedures:
#     circleMenu, createSphereAndAttachCircleNode
#

import maya.cmds as cmds

# Callback routine for the menu item created in CircleMenu
def createSphereAndAttachCircleNode(*args):
	# Create a circle node dependency object called "circleNode1"
	cmds.createNode("spCircle", name="circleNode1")

	# Create a sphere called "sphere1"
	cmds.sphere(name="sphere1", radius=1)

	# Connect the sine output attribute of "circleNode1"
	# to the X position of "sphere1"
	cmds.connectAttr("circleNode1.sineOutput", "sphere1.translateX")

	# Connect the cosine output attribute of "circleNode1"
	# to the Z position of "sphere1"
	cmds.connectAttr("circleNode1.cosineOutput", "sphere1.translateZ")

	# Connect the output of the time slider, "time1", in frames
	# to the input of "circleNode1".
	cmds.connectAttr("time1.outTime", "circleNode1.input")

	# "circleNode1" will now compute the X and Z positions of "sphere1"
	# as a function of the frame in the current animation.

def circleMenu():
	# The global string variable gMainWindow contains the name of top
	# Level Maya window.  Using this as the parent in a menu command
	# will create a new menu at the same level as "File", "Edit", etc.
	mainWindow = maya.mel.eval( "global string $gMainWindow;$temp = $gMainWindow" )

	# Create a top level menu called "Circle".  Its only menu item
	# is called "Move in circle", and when invoked by the user, it
	# will call the createSphereAndAttachCircleNode procedure shown above.
	cmds.menu("circleMenu", parent=mainWindow, tearOff=True, label="Circle")
	cmds.menuItem("circleMenuItem1", label="Move in circle", command=createSphereAndAttachCircleNode)

# Run circleMenu to add "Circle" to the top level Maya menu list.
circleMenu()
